<?php

/*
  Plugin Name: 80s Idea Ads In Content
  Plugin URI: http://80sidea.com/
  Description: 在正文中插入Adsense等广告,优化主题Twenty Ten, K2显示,将奇艺视频播放器设置为最新
  Version: 0.1.11.3.21
  Author: 最爱你是谁
  Author URI: http://80sidea.com/
 */

/*  Copyright 2010 最爱你是谁  (email : 023yangbo@gmail.com)

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

function idea_ads($content) {
	$adsense_468x60_pic = '<script type="text/javascript"><!--
google_ad_client = "ca-pub-7579614326865146";
/* 468x60 图片 */
google_ad_slot = "1543959425";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>';
	$adsense_468x15_link = '<script type="text/javascript"><!--
google_ad_client = "ca-pub-7579614326865146";
/* 468x15 */
google_ad_slot = "0951497661";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>';
	$adsense_468x60_txt_pic = '<script type="text/javascript"><!--
google_ad_client = "ca-pub-7579614326865146";
/* 468x60 */
google_ad_slot = "3809013314";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>';
	$search_640 = '<script type="text/javascript"><!--google_ad_client="pub-7579614326865146";google_ad_format="js_sdo";google_color_bg="FFBBE8";google_cts_mode="hq";google_num_cts="5";google_searchbox_width=190;google_searchbox_height=30;google_link_target=2;google_rs_pos="right";google_ad_height=30;google_ad_width=640;--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_sdo.js"></script>';
	$en_amazon_com = '<iframe src="http://rcm.amazon.com/e/cm?t=80sidea-20&o=1&p=13&l=ez&f=ifr&f=ifr" width="468" height="60" scrolling="no" marginwidth="0" marginheight="0" border="0" frameborder="0" style="border:none;"></iframe>';
	$jd = '<a href="http://click.union.360buy.com/JdClick/?unionId=4764&t=1&to=http://www.360buy.com" target="_blank"><img src="http://show.union.360buy.com/source/home/home-A-468x60.gif" /></a>';
	if (is_single ()) {
		$content_length = strlen ( $content );
		if ($content_length > 2000) {
			$content = $adsense_468x60_txt_pic . $content . $adsense_468x60_pic . $jd;
		} else {
			$content = $adsense_468x60_pic . $content . $adsense_468x60_txt_pic . $en_amazon_com . $jd;
		}
	}
	return $content;
}
add_filter ( 'the_content', 'idea_ads' );
//针对主题Twenty Ten优化显示
function idea_twentyten_css($post_ID) {
	$idea_css = '<style type="text/css">';
	$idea_css .= '#site-title {width: 670px;}';
	$idea_css .= '#site-description {text-align: right;width: 250px;}';
	if (is_single ()) {
		$idea_css .= '.entry-content img {margin: 0;height: auto;max-width: 690px;width: auto;}';
	}
	$idea_css .= '</style>';
	echo $idea_css;
}
//针对主题K2优化显示
function idea_k2_css($post_ID) {
	if (is_single ()) {
		$idea_css = '<style type="text/css">';
		$idea_css .= 'body.flankingsidebars.columns-three .primary {width: 715px;margin-left: 0;}';
		$idea_css .= '.entry-content img {margin: 0;height: auto;max-width: 715px;width: auto;display: block;margin-left: auto;margin-right: auto;}';
		$idea_css .= 'body.flankingsidebars.columns-three #widgets-sidebar-1 {left: 0;margin-left: 0;}';
		$idea_css .= '</style>';
		echo $idea_css;
	}
}
$theme = get_option ( 'template' );
if ($theme == 'twentyten') {
	add_action ( 'wp_head', 'idea_twentyten_css' );
}
if ($theme == 'k2') {
	add_action ( 'wp_head', 'idea_k2_css' );
}
//更新奇艺视频播放器为最新
function idea_qiyi_player($content) {
	$pattern = '|(<embed.*?src="http://www.qiyi.com/player/)\d*(/qiyi_player.swf"[^>]*?>)|';
	$replacement = '${1}20110422185049$2';
	$content = preg_replace ( $pattern, $replacement, $content );
	return $content;
}
add_filter ( 'the_content', 'idea_qiyi_player' );
function idea_google_analytics() {
	if (! is_admin ()) {
		$analytics_code = "<script type=\"text/javascript\">var _gaq=_gaq||[];_gaq.push(['_setAccount','UA-19660711-1']);
_gaq.push(['_setDomainName','.80sidea.com']);_gaq.push(['_trackPageview']);
(function(){var ga=document.createElement('script');ga.type='text/javascript';ga.async=true;
ga.src=('https:'==document.location.protocol?'https://ssl':'http://www')+'.google-analytics.com/ga.js';
var s=document.getElementsByTagName('script')[0];s.parentNode.insertBefore(ga,s)})();</script>";
		echo $analytics_code;
	}
}
add_action ( 'wp_head', 'idea_google_analytics' );
?>